<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人网盘</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 1px solid #ddd;
        }
        h1 {
            margin: 0;
        }
        .logout-btn {
            background-color: #f44336;
            color: white;
            padding: 8px 15px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
            margin-right: 10px;
        }
        .logout-btn:hover {
            background-color: #d32f2f;
        }
        .cancel-btn {
            background-color: #ff9800;
            color: white;
            padding: 8px 15px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
        }
        .cancel-btn:hover {
            background-color: #e68a00;
        }
        .upload-section {
            margin-bottom: 30px;
            padding: 20px;
            background-color: #f9f9f9;
            border-radius: 4px;
        }
        .file-input {
            margin-bottom: 10px;
        }
        .upload-btn {
            background-color: #4CAF50;
            color: white;
            padding: 10px 15px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        .upload-btn:hover {
            background-color: #45a049;
        }
        table {
            width: 100%;
            border-collapse: collapse;
        }
        th, td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        th {
            background-color: #f2f2f2;
        }
        .action-btn {
            padding: 5px 10px;
            margin-right: 5px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
        }
        .download-btn {
            background-color: #2196F3;
            color: white;
        }
        .download-btn:hover {
            background-color: #0b7dda;
        }
        .delete-btn {
            background-color: #f44336;
            color: white;
            padding: 5px 10px;
        }
        .delete-btn:hover {
            background-color: #d32f2f;
        }
        .share-btn {
            background-color: #ff9800;
            color: white;
            padding: 5px 10px;
        }
        .share-btn:hover {
            background-color: #e68a00;
        }
        .message {
            padding: 10px;
            margin-bottom: 20px;
            border-radius: 4px;
        }
        .success {
            background-color: #d4edda;
            color: #155724;
        }
        .error {
            background-color: #f8d7da;
            color: #721c24;
        }
        .no-files {
            text-align: center;
            color: #666;
            padding: 20px;
        }
    </style>
</head>
<body>
    <header>
        <h1>个人网盘</h1>
        <div>
            <a href="{{ url_for('logout') }}" class="logout-btn">退出登录</a>
            <a href="{{ url_for('cancel_account') }}" class="cancel-btn" onclick="return confirm('确定要注销账号吗？这将删除所有数据！');">注销账号</a>
            <a href="{{ url_for('bind_email') }}" class="logout-btn" style="background-color: #2196F3;">绑定邮箱</a>
        </div>
    </header>

    {% with messages = get_flashed_messages() %}
        {% if messages %}
            {% if '成功' in messages[0] %}
                <div class="message success">{{ messages[0] }}</div>
            {% else %}
                <div class="message error">{{ messages[0] }}</div>
            {% endif %}
        {% endif %}
    {% endwith %}

    <div class="upload-section">
        <h2>上传文件</h2>
        <form method="POST" action="{{ url_for('upload') }}" enctype="multipart/form-data">
            <div class="file-input">
                <input type="file" name="file" required>
            </div>
            <button type="submit" class="upload-btn">上传</button>
        </form>
    </div>

    <h2>我的文件</h2>
    {% if files %}
        <table>
            <thead>
                <tr>
                    <th>文件名</th>
                    <th>大小</th>
                    <th>上传日期</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for file in files %}
                    <tr>
                        <td>{{ file.filename }}</td>
                        <td>{{ (file.size / 1024)|round(2) }} KB</td>
                        <td>{{ file.upload_date.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                        <td>
                            <a href="{{ url_for('download', file_id=file.id) }}" class="action-btn download-btn">下载</a>
                            <a href="{{ url_for('share', file_id=file.id) }}" class="action-btn share-btn">分享</a>
                            <a href="{{ url_for('delete', file_id=file.id) }}" class="action-btn delete-btn" onclick="return confirm('确定要删除这个文件吗？');" style="display: inline-block; padding: 8px 12px;">删除</a>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% else %}
        <div class="no-files">暂无文件，请上传文件。</div>
    {% endif %}
</body>
</html>